import 'reflect-metadata'
export function Get(path = ''): MethodDecorator{
    return (target, propertyKey, decorator: PropertyDescriptor) => {
        Reflect.defineMetadata('path', path,decorator.value)
        Reflect.defineMetadata('method', 'GET',decorator.value)
    }
}

export function Post(path = ''): MethodDecorator{
    return (target, propertyKey, decorator: PropertyDescriptor) => {
        Reflect.defineMetadata('path', path,decorator.value)
        Reflect.defineMetadata('method', 'POST',decorator.value)
    }
}

export function Redirect(url = '/', statusCode = 302): MethodDecorator{
    return (target, propertyKey, decorator: PropertyDescriptor) => {
        Reflect.defineMetadata('redirectUrl', url,decorator.value)
        Reflect.defineMetadata('redirectStatusCode', statusCode,decorator.value)
    }
}

export function HttpCode( statusCode = 200): MethodDecorator{
    return (target, propertyKey, decorator: PropertyDescriptor) => {
        Reflect.defineMetadata('statusCode', statusCode,decorator.value)
    }
}
export function Header(name, value): MethodDecorator{
    return (target, propertyKey, decorator: PropertyDescriptor) => {
        const existingHeaders = Reflect.getMetadata('headers', decorator.value)??[]
        existingHeaders.push({name, value})
        Reflect.defineMetadata('headers', existingHeaders,decorator.value)
    }
}
